Repository navigation
OpenConceptLab/ocl_online#786 | Algorithm replies apply to the current list - #139
Conversation
…t list: custom algorithm check and bridge canonical URL no longer overwrite edits made while pending Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| const checkId = (customCheckIdRef.current[key] || 0) + 1; | ||
| customCheckIdRef.current[key] = checkId; | ||
|
|
||
| const token = tokenOverride ?? selected?.token; |
There was a problem hiding this comment.
Nit (optional): The stale-reply check only compares the URL. If the user edits the token while a check is pending, a 401 for the old token can still set tokenRequired after they typed a new one. Fix: also drop the reply (clearing isLoading) when the current token differs from the one sent.
There was a problem hiding this comment.
Fixed: the check compares the URL and token sent with the current entry; a change only stops loading.
| // (ocl_online#786). Each change sets it straight away, so changes made | ||
| // before the parent re-renders build on each other. | ||
| const latestValueRef = React.useRef(normalizedValue) | ||
| latestValueRef.current = normalizedValue |
There was a problem hiding this comment.
Nit (optional): latestValueRef is written during render. A render React discards under concurrent rendering can leave the ref holding a list that was never committed. Fix: assign it in a useLayoutEffect on normalizedValue, keeping commitValue's synchronous write.
There was a problem hiding this comment.
Fixed: the ref is set in a useLayoutEffect; commitValue still writes it straight away.
| assert.equal(next[0].description, 'typed while waiting') | ||
| assert.equal(next[0].id, 'x') | ||
| assert.equal(next[1], search) | ||
| assert.notEqual(next, atRequest) |
There was a problem hiding this comment.
Nit (optional): assert.notEqual(next, atRequest) always passes, since patchSelected never receives atRequest. The reply decision (newer check, removed, URL changed) lives in the component and is untested. Fix: drop the assertion and move that decision into selectedAlgos.js with tests.
There was a problem hiding this comment.
Fixed: dropped the assertion; the reply decision is customCheckReply in selectedAlgos.js, with tests.
| const next = normalizedValue.map(v => (v.__key === key ? { ...v, ...patch } : v)); | ||
| onChange(next); | ||
| const current = latestValueRef.current | ||
| commitValue(patchSelected(current, key, patch)); |
There was a problem hiding this comment.
Important: A bridge algorithm can end up with the canonical URL of a repo the user has since moved away from. The fetchBridgeCanonical(url).then(...) reply (line 241) now patches the current list through this function without checking that target_repo_url is still the one fetched, so a slow reply for repo A lands after the user switched to repo B. Fix: skip the patch unless the current entry still has target_repo_url === url.
There was a problem hiding this comment.
Fixed: the canonical reply is skipped unless the entry still has the fetched target_repo_url.
…d for a changed repo URL, custom check reply dropped for a changed token, latest-list ref set after commit, reply decision tested Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
snyaggarwal
left a comment
There was a problem hiding this comment.
Verdict: ready to merge. Nothing blocking. The follow-ups below are optional.
This fixes OpenConceptLab/ocl_online#786. A custom algorithm check or a bridge canonical URL reply no longer resets the list to how it was when the request started. Edits to other algorithms and fields made while it was pending are kept. A reply is dropped if the algorithm was removed, its URL or token changed, or a newer check started. npm test passes (766, 11 new) and CI is green.
Checked and fine:
- Removing and adding an algorithm both build on the current list. A remove then an add before the parent re-renders keeps both changes.
- Removing an algorithm clears its check, so a pending reply for it is ignored.
- The latest-list ref is set in a
useLayoutEffectafter each commit, so renders React throws away don't touch it.
Non-blocking:
- Fields the reply fills still win over typing. The check writes
id,nameanddescription, so text typed into those three while it is pending is replaced. That's reasonable, because the endpoint is the source for them. But the test "an edit made while a check was pending is kept" (selectedAlgos.test.js:22) patches onlyidandname, so it suggests more than the component does. Rename it, or have it use the real patch shape. - A canonical URL typed while its fetch is pending is overwritten (
MultiAlgoSelector.jsx:243). The reply is dropped only whentarget_repo_urlchanged. It could also sendbridge_repo: sel.bridge_repo, so a typed value counts as a change. - An update to the list from
MapProject(for examplepinVersion) can be lost. This happens if it is queued in the same gap before a render as a reply from this component, becausecommitValuepasses a whole list tosetAlgosSelectedrather than a function. It's narrow, and it was worse before. Fully closing it needs a functionalonChange. isLoadingcan stay true for a key the parent replaced while its check was pending, for example on project load. Nothing readsisLoadingin the render today, so it can't be seen.- Pre-existing: the duplicate id/name check matches the entry against itself (
MultiAlgoSelector.jsx:219). Running the same check again can flag a conflict. Leave the entry's own key out of the search.
Nearby wording that belongs outside the open repo is noted on OpenConceptLab/ocl_online#532.
Fixes OpenConceptLab/ocl_online#786.
Problem
verifyCustomAlgorithmawaited the algorithm's URL, then calledupdateSelected, which mapped overnormalizedValuefrom the render that sent the request. Any edit to the algorithm list made while the check was pending (another field, another algorithm added or removed) was overwritten by the reply. The bridge canonical URL fetch had the same problem: its.thencalled theupdateSelectedcaptured by an earlier effect run.Change
MultiAlgoSelectorkeeps the current list in a ref (latestValueRef).updateSelected,removeSelectedand adding an algorithm all build on it throughcommitValue, which updates the ref right away, so changes made before the parent re-renders build on each other.useLayoutEffectafter each commit, andcommitValuewrites it straight away.target_repo_urlchanged while the fetch was pending.patchSelected,isStaleReplyandcustomCheckReplyinselectedAlgos.js, with tests.Testing
npm test: 766 pass (11 new inselectedAlgos.test.js).🤖 Generated with Claude Code